﻿@using GP.Logic.Model
@model ICollection<Citizen>
@{
    ViewBag.Title = "Index";
}

<h2>Citizens</h2>

@Html.ActionLink("Create new citizen", MVC.Citizen.CreateCitizen())

<table>
    <tr>
        <th>
            CitizenId
        </th>
        <th>
            Name
        </th>
        <th>
            Doctor
        </th>
        <th>
            Granted access to
        </th>
        <th>
            Email
        </th>
        <th>
            Phone
        </th>
        <th>
            PassKey
        </th>
        <th>
            Time created
        </th>
        <th>
            SocialSecurity
        </th>
        <th></th>
        <th></th>
    </tr>
    @foreach(var item in Model)
    {
        <tr>
            <td>@item.CitizenId</td>
            <td>@item.Name</td>
            <td>@item.Doctor.Name</td>
            <td>
                @foreach (var d in item.GratedAccessTos.Select(a => a.Doctor))
                { 
                    @d.Name 
                    <br />
                }
            </td>
            <td>@item.Email</td>
            <td>@item.Phone</td>
            <td>@item.PassKey</td>
            <td>@item.TimeCreated</td>
            <td>@item.SocialSecurity</td>
            <td>
                @Html.ActionLink("Edit", MVC.Citizen.Edit(item.CitizenId))
            </td>
            <td>
                @if (item.GratedAccessTos.Count == 0 && item.Events.Count == 0)
                { 
                    @Html.ActionLink("Delete", MVC.Citizen.Delete(item.CitizenId))
                }
            </td>
        </tr>
    }
</table>

